package com.xykj.enterprise.wechat.ext.api.externalcontact;

import com.xykj.enterprise.wechat.bean.ext.externalcontact.TransferResultVo;
import com.xykj.enterprise.wechat.ext.service.customer.ExternalContactService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Slf4j
@Function(description = "查询客户接替状态", parameters = {
        @Parameter(name = "access_token", type = Type.String, description = "access_token", required = true),

        @Parameter(name = "handover_userid", type = Type.String, description = "原跟进成员的userid", required = true),
        @Parameter(name = "takeover_userid", type = Type.String, description = "接替成员的userid", required = true),
        @Parameter(name = "cursor", type = Type.String, description = "分页查询的cursor，每个分页返回的数据不会超过1000条；不填或为空表示获取第一个分页；", required = false),
})
@Component
public class TransferResignedResult implements Action {

    @Autowired
    ExternalContactService externalContactService;

    @Override
    public Response execute(Request request) throws Exception {
        String handover_userid = request.getString("handover_userid");
        String takeover_userid = request.getString("takeover_userid");
        String cursor = request.getString("cursor");

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("handover_userid", handover_userid);
        params.put("takeover_userid", takeover_userid);
        if (cursor != null) {
            params.put("cursor", cursor);
        }

        TransferResultVo rsp = externalContactService.transferResignedResult(
                request.getString("access_token"),
                params
        );
        if (rsp.getErrcode() != 0) {
            return Response.fail(rsp.getErrmsg());
        }
        return Response.success().put("data", rsp);
    }
}
